﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Model;
using Model.FA_DataSetTableAdapters;
using Model.IRepository;
using Model.Repository;

namespace ASP_FORMS
{
    /// <summary>
    /// Summary description for CheckUser
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class CheckUser : System.Web.Services.WebService
    {
        UserRepository _repUser = new UserRepository();
        FA_DataSet.UsersDataTable DT_Users;

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod]
        public bool IsValidUser(string Username, string Password)
        {
            try
            {
                DT_Users = _repUser.IsAuthenticatedUser(Username, Password);
                if (DT_Users != null)
                {
                    if (DT_Users.Count == 0)
                    {
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        [WebMethod]        
        public bool IsUsernameAvailable(string Username)
        {
            try
            {
                var re = _repUser.IsUsernameAvailable(Username);
                return re;
            }
            catch (Exception ex)
            {
                return false;

            }
        }
    }
}
